#include "hitbox.h"

Hitbox::Hitbox(int x, int y, int w, int h)
{
	xy = new Vector((float)x, (float)y);
	wh = new Vector((float)w, (float)h);
	for(int i=0; i<4; i++)
		worldCoords[i] = 0;
}
Hitbox::Hitbox()
{
	xy = 0;
	wh = 0;
	for(int i=0; i<4; i++)
		worldCoords[i] = 0;
}
Hitbox::~Hitbox()
{
	if(xy != 0)
		delete xy;
	if(wh != 0)
		delete wh;
	for(int i=0; i<4; i++)
	{
		if(worldCoords[i] != 0)
			delete worldCoords[i];
	}
}
void Hitbox::setDimensions(int x, int y, int w, int h)
{
	if(xy != 0)
		delete xy;
	if(wh != 0)
		delete wh;

	xy = new Vector((float)x, (float)y);
	wh = new Vector((float)w, (float)h);
}
void Hitbox::calcWorldCoords(int xoffset, int yoffset, float angle)
{
	worldCoords[0] = new Vector(xoffset+((cos(angle) * -wh->getX() - sin(angle) * -wh->getY())+xy->getX()) ,yoffset+((sin(angle) * -wh->getX() + cos(angle) * -wh->getY())+xy->getY()));
	worldCoords[1] = new Vector(xoffset+((cos(angle) * -wh->getX() - sin(angle) * wh->getY())+xy->getX()),yoffset+((sin(angle) * -wh->getX() + cos(angle) * wh->getY())+xy->getY()));
	worldCoords[2] = new Vector(xoffset+((cos(angle) * wh->getX() - sin(angle) * wh->getY())+xy->getX()),yoffset+((sin(angle) * wh->getX() + cos(angle) * wh->getY())+xy->getY()));
	worldCoords[3] = new Vector(xoffset+((cos(angle) * wh->getX() - sin(angle) * -wh->getY())+xy->getX()),yoffset+((sin(angle) * wh->getX() + cos(angle) * -wh->getY())+xy->getY()));
}
void Hitbox::clearWorldCoords()
{
	for(int i=0; i<4; i++)
		delete worldCoords[i];
}
Vector *Hitbox::getWorldCoord(int i)
{
	return worldCoords[i];
}
